package com.outside.landingpage.controller;

import com.outside.landingpage.model.RedirectAddress;
import com.outside.landingpage.service.LandingPageConfigService;
import com.outside.landingpage.util.LogTool;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.io.ResolverUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import org.springframework.web.servlet.view.RedirectView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;

import java.util.HashMap;

@Controller
@RequestMapping(value = "landing/page")
public class LandingPageConfigController {
    private Logger logger = LogTool.getLog("LandingPageConfigController");
    @Resource
    private LandingPageConfigService landingPageConfigService;

    @GetMapping(value = "view")
    public String index(@Param("id") String id, HttpServletRequest request, RedirectAttributes redirectAttributes) {
        RedirectAddress redirectAddress = landingPageConfigService.verifyCountry(id, request);
        if (redirectAddress == null) {
            return "redirect:http://www.afegfs.com/page/403.html";
        } else {
//            redirectAttributes.addAttribute("ln", redirectAddress.getLink());
            return "redirect:" + redirectAddress.getAddress();
        }
    }
    @GetMapping(value = "/baidu")
    public String baidu(RedirectAttributes redirectAttributes) {
        logger.info("进来了");

//        redirectAttributes.addFlashAttribute("test", "test");
        redirectAttributes.addAttribute("test", "https://chat.whatsapp.com/FRfm9rGhOnW8HL9DDSNcCm");
//        String url = "http://www.hthdg.shop/page/ppeleven/index.html"; // 要重定向的目标URL
//        RedirectView redirectView = new RedirectView(url);
//        redirectView.addStaticAttribute("test", "ResolverUtil.Test");
        return "redirect:http://www.hthdg.shop/page/ppeleven/index.html";
    }
}
